<template>
	<view class="info-popup">
		<view class="info-popup-con">
			<view class="info-popup-con-head">
				<view class="info-popup-con-elevator" v-if="selectCabinet.model_code == 'TH80'">
					<view class="info-popup-con-elevator-item" @click="runElevator(selectCabinet.registeras, 0)">
						上升
					</view>
					<view class="info-popup-con-elevator-item" @click="runElevator(selectCabinet.registeras, 1)">
						下降
					</view>
				</view>
				<view class="info-popup-con-head-title">补料确认</view>
				<view class="info-popup-con-head-close" @click="closeInfoPopup()"><uni-icons type="closeempty"
						size="22" color="#fff"></uni-icons></view>
			</view>
			<view class="info-popup-con-body">
				<view class="info-popup-con-body-left">
					<image class="info-popup-con-body-left-img" :src="material.picture" mode="aspectFill"></image>
				</view>
				<view class="info-popup-con-body-right">
					<view class="info-popup-con-body-right-item">
						<text class="info-popup-con-body-right-item-title">品牌：</text>
						<text
							class="info-popup-con-body-right-item-value">{{ material.brand ? material.brand : '-' }}</text>
					</view>
					<view class="info-popup-con-body-right-item">
						<text class="info-popup-con-body-right-item-title">型号：</text>
						<text
							class="info-popup-con-body-right-item-value">{{ material.specifications ? material.specifications : '-' }}</text>
					</view>
					<view class="info-popup-con-body-right-item">
						<text class="info-popup-con-body-right-item-title">单位数：</text>
						<text class="info-popup-con-body-right-item-value">{{ material.packing_count }}</text>
					</view>
					<view class="info-popup-con-body-right-item">
						<text class="info-popup-con-body-right-item-title">物料编码：</text>
						<text
							class="info-popup-con-body-right-item-value">{{ material.number ? material.number : '-' }}</text>
					</view>
				</view>
			</view>
			<!-- <view class="info-popup-con-print" @click="selectPrint = !selectPrint">
				<text class="info-popup-con-print-title">打印</text>
				<view class="info-popup-con-print-select"><uni-icons v-if="selectPrint" type="checkmarkempty" size="14px"></uni-icons></view>
			</view> -->
			<view class="info-popup-con-stock">
				<view class="info-popup-con-stock-con">
					<view class="info-popup-con-stock-con-name">
						<text class="info-popup-con-stock-con-name-value">{{ material.material_name }}</text>
						<text class="info-popup-con-stock-con-name-value" v-if="isPeel">{{peel}}盒</text>
					</view>
					<view class="info-popup-con-stock-con-track">
						<text class="info-popup-con-stock-con-track-title">货道:</text>
						<text class="info-popup-con-stock-con-track-value">
							{{ selectCabinet.st_name }}-{{ selectCabinet.custom_identification ? selectCabinet.custom_identification : selectCabinet.identification }}
						</text>

					</view>
					<view class="info-popup-con-stock-con-num">
						<text class="info-popup-con-stock-con-num-title">补料数量：</text>
						<input class="info-popup-con-stock-con-num-inp" type="number" v-model="infoPopupNum" />

					</view>
				</view>
				<view class="info-popup-con-stock-submit" @click="submit()">
					<text class="info-popup-con-stock-submit-text">{{sub}}</text>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	const API = require("../../../../utils/apiConfig.js");
	export default {
		name: 'info-popup',
		props: {
			material: {
				type: Object,
				default: () => {
					return {};
				}
			},
			selectCabinet: {
				type: Object,
				default: () => {
					return {};
				}
			},
			peel: {
				type: Number,
				default: () => {
					return 0;
				}
			},
			workId: {
				type: String,
				default: () => {
					return '';
				}
			},
			supplmentNum: {
				type: Number,
				default: () => {
					return 0;
				}
			},
			workOrder: {
				type: Boolean,
				default: false
			}

		},
		data() {
			return {
				infoPopupNum: 1, //补货数量
				selectPrint: false, //选择打印
				hasClickSubmit: false, //防止重复提交
				materialList: [], //将传入的物料放到物料数组用于称重遍历和修改称重值
				pageActivity: true,
				loopGetMaterialWeightStatus: false, //是否正在循环获取所有称重，用于还在读取称重值时阻止退出页面
				loopGetMaterialWeightStatusTimer: null, //检测指令出错异常定时器
				hasPositionLampStatus: false, //是否有开门称重货道指示灯
				changeWarnLampTimer: null, //告警灯定时器
				navigateBackTimer: null, //提交完成提示返回定时器
				isScan: false,
				isPeel: false, //是否去皮
				isFB: false, //正反转
				sub: '提交'
			};
		},

		async mounted() {
			console.log('选择的物料==', this.material);
			console.log('选择的货道==', this.selectCabinet);


		},
		methods: {

			// 对货道进行补货
			async submit() {
				if (this.infoPopupNum > this.selectCabinet.capacity - this.selectCabinet.now_num) {
					uni.showToast({
						title: '超出货道容量',
						icon: 'none'
					});
					return;
				}
				if (this.infoPopupNum < 1) {
					uni.showToast({
						title: '非法数量',
						icon: 'none'
					});
					return;
				}
				if (this.hasClickSubmit) {
					console.log('请勿重复提交');
					return;
				}
				this.hasClickSubmit = true;
				uni.showLoading({
					title: '请稍等',
					mask: true
				});
				API.supplement({
					work_id: this.workId,
					id: this.selectCabinet.id, //货道id
					num: this.infoPopupNum, //补货数量
					material_id: this.material.id, //物料id
					identification: this.selectCabinet.identification, //货道标识
					model_code: this.selectCabinet.model_code, //模型号
					custom_id: this.material.custom_id //第三方自定义id
				}).then((res)=>{
					this.hasClickSubmit = false;
					uni.hideLoading();
					this.$emit('getNewData')
				})
			},
			async closeInfoPopup() {
				this.hasClickSubmit = false;
				this.infoPopupNum = 0;
				this.$emit('closeInfoPopup');
			},



		},
		destroyed() {
			// console.log('组件销毁');
			clearTimeout(this.navigateBackTimer);
			clearTimeout(this.changeWarnLampTimer);
			
			this.pageActivity = false;
			getApp().globalData.weightOperate = false;
			uni.$off('keydownStrComplete', this.scan);

		}
	};
</script>

<style lang="scss">
	.info-popup {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 998;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: rgba(0, 0, 0, 0.4);

		.info-popup-con {
			// position: absolute;
			// top: 20vh;
			width: 500rpx;
			max-width: 600px;
			border-radius: 12px;
			overflow: hidden;
			background-color: #ffffff;

			.info-popup-con-head {
				margin-bottom: 5px;
				position: relative;
				height: 64rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				background-color: #333847;

				.info-popup-con-elevator {
					position: absolute;
					top: 13px;
					left: 10px;
					height: 40px;
					display: flex;
					flex-direction: row;
					justify-content: space-between;

					.info-popup-con-elevator-item {
						width: 70px;
						font-size: 16rpx;
						background-color: #ffffff;
						color: #414141;
						margin-right: 10px;
						border-radius: 8px;
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;
					}
				}

				.info-popup-con-head-title {
					font-size: 26rpx;
					color: #fff;
					font-weight: bold;
				}

				.info-popup-con-head-close {
					position: absolute;
					right: 0;
					top: 0;
					padding: 10rpx;
				}
			}

			.info-popup-con-body {
				padding: 5px;
				display: flex;
				flex-direction: row;
				align-items: center;

				.info-popup-con-body-left {
					display: flex;
					flex-direction: column;

					.info-popup-con-body-left-img {
						max-width: 180rpx;
						max-height: 180rpx;
						width: 150px;
						height: 150px;
						display: block;
						overflow: hidden;
						border-radius: 6px;
						box-shadow: 1px 2px 2px 2px rgba(0, 0, 0, 0.1);
					}
				}

				.info-popup-con-body-right {
					flex: 1;
					height: 120px;
					max-height: 150rpx;
					padding-left: 15px;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.info-popup-con-body-right-item {
						padding: 2px 0;
						display: flex;
						flex-direction: row;
						align-items: center;
						border-bottom: 1px solid #eee;
						justify-content: space-between;

						.info-popup-con-body-right-item-title {
							font-size: 20rpx;
							line-height: 18px;
							height: 18px;
							flex-shrink: 0;
						}

						.info-popup-con-body-right-item-value {
							// text-align: right;
							word-break: break-all;
							font-size: 20rpx;
							line-height: 18px;
							height: 18px;
						}
					}
				}
			}

			.info-popup-con-print {
				padding: 0 20px;
				height: 28px;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;

				.info-popup-con-print-title {
					font-size: 20rpx;
					line-height: 18px;
					height: 18px;
				}

				.info-popup-con-print-select {
					width: 18px;
					height: 18px;
					// background-color: #ffffff;
					border: 1px solid #aaa;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
				}
			}

			.info-popup-con-stock {
				padding: 10px;

				.info-popup-con-stock-con {
					padding: 10px;
					border-radius: 4px;
					border: 1px solid #eee;
					background-color: #f5f5f5;

					.info-popup-con-stock-con-name {
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						.info-popup-con-stock-con-name-value {
							font-size: 20rpx;
							font-weight: bold;
						}
					}

					.info-popup-con-stock-con-track {
						margin-top: 10px;
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						.info-popup-con-stock-con-track-title {
							font-size: 20rpx;
							color: #555;
						}

						.info-popup-con-stock-con-track-value {
							font-size: 20rpx;
							color: #555;
						}
					}

					.info-popup-con-stock-con-num {
						margin-top: 8px;
						display: flex;
						flex-direction: row;
						align-items: center;

						.info-popup-con-stock-con-num-title {
							font-size: 20rpx;
							color: #555;
							flex-shrink: 0;
						}

						.info-popup-con-stock-con-num-inp {
							flex: 1;
							height: 40px;
							box-sizing: border-box;
							padding: 0 10px;
							border: 1px solid #eee;
							font-size: 20rpx;
							background-color: #ffffff;
						}

						.info-popup-con-stock-con-num-btns {
							display: flex;
							flex-direction: row;

							.info-popup-con-stock-con-num-btns-item {
								width: 40px;
								height: 40px;
								box-sizing: border-box;
								border: 1px solid #fff;
								margin-left: 5px;
								border-radius: 2px;
								display: flex;
								flex-direction: column;
								justify-content: center;
								align-items: center;
								color: #ffffff;
								font-size: 24px;
								background-color: #333847;

								&.full {
									font-size: 20rpx;
								}
							}
						}
					}
				}

				.info-popup-con-stock-submit {
					height: 64rpx;
					margin-top: 8px;
					border-radius: 6px;
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;
					background-color: #333847;

					&:active {
						background-color: #695f48;
					}

					.info-popup-con-stock-submit-text {
						color: #ffffff;
						font-size: 20rpx;
					}
				}

				.info-popup-con-stock-submit_text {
					height: 64px;
					margin-top: 10px;
					border-radius: 6px;
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;
					background-color: #ffffff;


					.info-popup-con-stock-submit-text1 {
						color: #000000;
						font-size: 24px;
					}
				}
			}
		}
	}
</style>